import api from './axios'
import {objToQuery} from '../utils/common'
import {md5Str} from '../utils/md5'

export const loginAPI = async (username, password) => {
  try {
    const res = await api('auth2/Login', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      data: objToQuery({
        authType: 'localpass',
        authSecret: md5Str(password),
        authIDType: 'userid2',
        authID: username
      })
    })
    return res
  } catch (e) {
    throw e
  }
}

export const getTokenInfoAPI = async () => {
  try {
    const res = await api('auth2/GetTokenInfo')
    return res
  } catch (e) {
    throw e
  }
}
